package entities

import (
	"gitee.com/igolang/imoney/internal/app/system/entities/constants"
	"gitee.com/igolang/imoney/internal/models/model"
	"slices"
)

type LoginUserReq struct {
	Password string `json:"password" form:"password" binding:"required"`
	Username string `json:"username" form:"username" binding:"required"`
	Code     string `json:"code" form:"code"`
	Uuid     string `json:"uuid" form:"uuid"`
}

type LoginResult struct {
	Status string
	Msg    string
	T      string
	Id     string
}

type LoginUserInfo struct {
	Permissions []string `json:"permissions"`
	Roles       []string `json:"roles"`
	User        struct {
		*model.SysUser
		Dept  *model.SysDept   `json:"dept"`
		Roles []*model.SysRole `json:"roles"`
	} `json:"user"`
}

func (u *LoginUserInfo) IsSuperAdmin() bool {
	if u.User.UserID == constants.SuperAdminId || slices.Contains(u.Roles, constants.SuperAdmin) {
		return true
	}
	return false
}

func (u *LoginUserInfo) HasPermission(per string) bool {
	if slices.Contains(u.Permissions, constants.AllPermission) {
		return true
	}
	return slices.Contains(u.Permissions, per)
}
